/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain;

/**
 *
 * @author Ripper
 */
public class LevelupAttributeManager 
{
    private LevelupAttribute[] attributes = {
        LevelupAttribute.MAX_HP, 
        LevelupAttribute.MAX_MANA,
        LevelupAttribute.MAX_STAMINA,
        LevelupAttribute.HP_REGEN,
        LevelupAttribute.MP_REGEN,
        LevelupAttribute.SP_REGEN,
        LevelupAttribute.PRCT_LIFESTEAL,
        LevelupAttribute.PRCT_SPELLVAMP,
        LevelupAttribute.PRCT_PHYS_DMG,
        LevelupAttribute.PRCT_MGC_DMG,
        LevelupAttribute.PRCT_ARM,
        LevelupAttribute.PRCT_MGC_ARM,
        LevelupAttribute.MOVEMENT,
        LevelupAttribute.ATK_SPD};
    private String[] attributeDescriptions = {
        "maximum hitpoints",
        "maximum mana",
        "maximum stamina",
        "hitpoint regen",
        "mana regen",
        "stamina regen",
        "% lifesteal",
        "% spellvamp",
        "% physical damage",
        "% magical damage",
        "% armor",
        "% magical armor",
        "movement",
        "attack speed"
    };
    
    private double[] attributeValues = {10, 10, 10, 0.10, 0.5, 0.5,
                                        0.25, 0.25, 1, 1, 1, 1, 1, 1,
                                        25, 2};
    
    private int[] attributePointsSpent = {};
    private int[] limitOnAttributesSpent = {0, 0, 0, 0, 0, 0, 
                                            0, 0, 0, 0, 0, 0,
                                            50, 50}; //0 = limitless
    
    public LevelupAttributeManager()
    {
        int[] resetPoints = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
        attributePointsSpent = resetPoints;
    }
    public int getMaximumPointsSpentIn(int index)
    {
        return limitOnAttributesSpent[index];
    }
    public int getAttributeCount()
    {
        return attributes.length;
    }
    public int getPointsSpentIn(int index)
    {
        return attributePointsSpent[index];
    }
    
    public LevelupAttributeManager(int[] pointsSpent)
    {
        attributePointsSpent = pointsSpent;
    }
    
    public String getAttributeDescription(int index)
    {
        return "+"+attributeValues[index]+" "+attributeDescriptions[index];
    }
    public double getAttributeSingleValue(int index)
    {
        return attributeValues[index];
    }
    public double getAttributeValue(int index)
    {
        return attributeValues[index] * (double)attributePointsSpent[index];
    }
    public double getAttributeValue(LevelupAttribute description)
    {
        int i = 0;
        for(int a = 0; a < attributes.length; a++)
        {
            if(attributes[a] == description)
            {
                i = a;
                break;
            }
        }
        
        return getAttributeValue(i);
    }
    
    public int attributePointsSpent()
    {
        int total = 0;
        for(int i: attributePointsSpent)
        {
            total += i;
        }
        return total;
    }
    public int attributePointsAvailable(int lvl)
    {
        return lvl - attributePointsSpent();
    }
    public boolean spendPoint(int index, int level)
    {
        if((attributePointsSpent[index] < limitOnAttributesSpent[index] || limitOnAttributesSpent[index] == 0)
                && attributePointsAvailable(level) > 0)
        {
            attributePointsSpent[index] = attributePointsSpent[index] + 1;
            return true;
        }
        return false;
    }
}
